package com.example.myapplication

import android.annotation.SuppressLint
import android.view.View
import com.example.myapplication.bean.User
import com.ftw.commons.BaseFragment
import com.ftw.commons.widgets.toast.ToastUtils
import com.google.gson.Gson
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity
import kotlinx.android.synthetic.main.fragment_mine.*

/**
 * 描    述：我的
 * 作    者：wenjun
 * 时    间：2019/4/23  11:30 AM
 */
class LoginFragment : BaseFragment(), LoginContract.View {

    private val mPresenter: LoginContract.Presenter by lazy { getPresenter() }

    @SuppressLint("CheckResult")
    override fun initView(view: View) {
        showOrHideTop(true)
        setTitle("执行Github登录")
        btn_login.setOnClickListener {
            mPresenter.login(
                mContext,
                et_address.text.toString().trim(),
                et_pwd.text.toString().trim()
            )
        }
    }


    override fun loadData() {
    }

    @SuppressLint("SetTextI18n")
    override fun loginComplete(user: User) {
        tv_result.setText("一下是结果：" + Gson().toJson(user))
    }


    override fun getPresenter(): LoginContract.Presenter = LoginPresenter(this)

    override fun getContentViewId(): Int {
        return R.layout.fragment_mine
    }

    override fun onError(code: Int, msg: String) {
        ToastUtils.showError(mContext, msg)
    }

    override fun onGet(): RxAppCompatActivity = getParentActivity()
}